import 'dart:convert';
import 'package:crypto/crypto.dart';


// 过期时间
const String expiration = '2075-01-01T12:00:00.000Z';
class OssUtil {
  //验证文本域
  static const String _policyText =
      '{"expiration": "$expiration","conditions": [["content-length-range", 0, 1048576000]]}'; //UTC时间+8=北京时间


  static String ossAccessKeyId = 'LTAI5tQCWBrqopVRN3B8iD5S';

  static String ossAccessKeySecret = '1BS2hdEcX01JQcJF4ZbS6W8EEkueJk';

  static String ossURL = 'https://img.liangce.cc';

  static String videoOssURL = 'https://video.liangce.cc';

  //进行utf8编码
  // ignore: non_constant_identifier_names
  static List<int> _policyText_utf8 = utf8.encode(_policyText);
  //进行base64编码
  static String policy = base64.encode(_policyText_utf8);

  //再次进行utf8编码
  // ignore: non_constant_identifier_names
  static List<int> _policy_utf8 = utf8.encode(policy);

  /*
  *获取signature签名参数
  */
  static String getSignature(String _accessKeySecret) {
    //进行utf8 编码
    // ignore: non_constant_identifier_names
    List<int> AccessKeySecretUtf8 = utf8.encode(_accessKeySecret);
    //通过hmac,使用sha1进行加密
    List<int> signaturePre =
        new Hmac(sha1, AccessKeySecretUtf8).convert(_policy_utf8).bytes;
    //最后一步，将上述所得进行base64 编码
    String signature = base64.encode(signaturePre);
    return signature;
  }

}

